package vn.hust.homebudget.exception;

import vn.hust.homebudget.core.broadcastreceiver.BudgetBroadcastReceiverConstant;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;


public class BudgetException extends Exception {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6077578378785899917L;
	private Integer errorCode;

	/**
	 * @param errorCode
	 *            the errorCode
	 * @param message
	 *            the error message
	 */
	public BudgetException(Integer errorCode, String message) {
		super(message);
		this.errorCode = errorCode;
	}

	/**
	 * @param message
	 *            the error message
	 */
	public BudgetException(String message) {
		super(message);
	}

	/**
	 * @param message
	 *            the error message
	 * @param cause
	 *            the {@link Throwable} object that has caused this error
	 */
	public BudgetException(String message, Throwable cause) {
		super(message, cause);
	}

	/**
	 * @return the errorCode
	 */
	public Integer getErrorCode() {
		return errorCode;
	}

	/**
	 * @param errorCode
	 *            the errorCode to set
	 */
	public void setErrorCode(Integer errorCode) {
		this.errorCode = errorCode;
	}
	/** send broadcast Error message with CLASSNAME bundle and MSG bundle to the application*/
	public void sendBroadCastErrorWithClassName(Context context) {
		Intent intent = new Intent(BudgetBroadcastReceiverConstant.BROADCAST_ACTION_EXCEPTION);
		Bundle broadcastBundle = new Bundle();
		broadcastBundle.putString(BudgetBroadcastReceiverConstant.BROADCAST_BUNDLE_MSG,getMessage());
		broadcastBundle.putString(BudgetBroadcastReceiverConstant.BROADCAST_BUNDLE_CLASSNAME,context.getClass().getName());
		intent.putExtras(broadcastBundle);
		context.sendBroadcast(intent);
	}
	/** send broadcast Error message without CLASSNAME bundle to the application*/
	public void sendBroadCastError(Context context) {
		Intent intent = new Intent(BudgetBroadcastReceiverConstant.BROADCAST_ACTION_EXCEPTION);
		Bundle broadcastBundle = new Bundle();
		broadcastBundle.putString(BudgetBroadcastReceiverConstant.BROADCAST_BUNDLE_MSG,getMessage());
		intent.putExtras(broadcastBundle);
		context.sendBroadcast(intent);
	}
	/** send broadcast Error message with ACTION NAME, CLASSNAME bundle and MSG bundle to the application*/
	public void sendBroadCastErrorWithClassName(String ACTION, Context context) {
		Intent intent = new Intent(ACTION);
		Bundle broadcastBundle = new Bundle();
		broadcastBundle.putString(BudgetBroadcastReceiverConstant.BROADCAST_BUNDLE_MSG,getMessage());
		broadcastBundle.putString(BudgetBroadcastReceiverConstant.BROADCAST_BUNDLE_CLASSNAME,context.getClass().getName());
		intent.putExtras(broadcastBundle);
		context.sendBroadcast(intent);
	}
	/** send broadcast Error message with ACTION NAME and without CLASSNAME bundle to the application*/
	public void sendBroadCastError(String ACTION, Context activity) {
		Intent intent = new Intent(ACTION);
		Bundle broadcastBundle = new Bundle();
		broadcastBundle.putString(BudgetBroadcastReceiverConstant.BROADCAST_BUNDLE_MSG,getMessage());
		intent.putExtras(broadcastBundle);
		activity.sendBroadcast(intent);
	}
}
